#include"date.h"

Date::Date(const int& j, const int& m, const int& a): j_(j),
													  m_(m),
													  a_(a)
{
}

int Date::getDay() const
{
	return j_;
}

int Date::getMonth() const
{
	return m_;
}

int Date::getYear() const
{
	return a_;
}

void Date::setDay(const int& j)
{
	j_ = j;
}

void Date::setMonth(const int& m)
{
	m_ = m;
}

void Date::setYear(const int& a)
{
	a_ = a;
}

bool Date::est_bissextile(int annee){
	return ((annee%4==0)&&(annee%100!=0))||((annee%100==0)&&(annee%400==0));
}

Date Date::lendemain() const{
	Date d(*this);
	++ d.j_;
	if(d.j_>nbJours(d.m_, d.a_))
	{
		d.j_=1;
		++d.m_;
		if(d.m_>12)
		{
			d.m_=1;
			++d.a_;
		}
	}
	return d;
}

int Date::nbJours(const int& m, const int& a)
{
	int nbjour = 0;
	
	if((m==1) || (m==3) || (m==5) || (m==8) || (m==10) || (m==12)){
		nbjour = 31;
	} else if(m==2){
		if(est_bissextile(a)){
			nbjour = 29;
		} else {
			nbjour = 28;
		}
	} else {
		nbjour = 30;
	}
	return nbjour;
}

bool Date::operator==(const Date& d) const
{
    return j_==d.j_ && m_ == d.m_ && a_==d.a_;
}

std::ostream& operator<<(std::ostream& os, const Date& d)
{
	os << (d.getDay()) << "\\" << (d.getMonth()) << "\\" << (d.getYear());
	return os;
}

